from sqlalchemy.orm import declarative_base
from sqlalchemy import Column, Integer, String, Text, DateTime, Float

Base = declarative_base()

class Danmaku(Base):
    __tablename__ = 'danmu'
    __table_args__ = {'comment': '弹幕表'}  # 表注释

    id = Column(Integer, primary_key=True, autoincrement=True)
    create_time = Column(DateTime, comment='插入时间')
    is_del = Column(Integer, server_default='0', comment='删除状态')
    content = Column(String(320), comment='弹幕内容')
    danmu_time = Column(DateTime, comment='弹幕出现时间')
    danmu_user = Column(String(320), comment='所属用户姓名')
    uuid = Column(String(36), comment='唯一标识')
    user_mid = Column(String(20), comment='用户uid')
    medal_level = Column(Integer, comment='粉丝牌等级')
    medal_name = Column(String(30), comment='粉丝牌名字')
    medal_from_user = Column(String(100), comment='粉丝牌归属主播')
    medal_from_uid = Column(Integer, comment='粉丝牌归属主播uid')
    honor_level = Column(Integer, server_default='-1', comment='荣誉等级')
    guard_level = Column(Integer, server_default='-1', comment='身份 3舰长 2提督 1总督 0粉丝 -1路人')
    room_real_id = Column(Integer, comment='弹幕发言直播间号')

    def __repr__(self):
        return f"<Danmu(id={self.id}, content='{self.content}', user='{self.danmu_user}')>"

class Gift(Base):
    """礼物数据表"""
    __tablename__ = "gift"
    id = Column(Integer, primary_key=True)
    gift_id = Column(Integer)                  # 礼物ID
    gift_name = Column(String(50))             # 礼物名称
    count = Column(Integer)                    # 礼物数量
    price = Column(Float)                      # 单价
    total = Column(Float)                      # 总价值
    sender_uid = Column(String(32))
    receiver_uid = Column(String(32))
    timestamp = Column(DateTime)

class OnlineRankCount(Base):
    """在线人数"""
    __tablename__ = "online_rank_count"
    id = Column(Integer, primary_key=True)
    online_count = Column(Integer, comment='在线人数')
    room_real_id = Column(Integer, comment='直播间号')
    create_time = Column(DateTime, comment='插入时间')